import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2024-01-25
 * Time: 14:24
 */
//阻塞队列可以很好的解耦合和削峰填谷
public class ThreadDemo2 {
    public static void main(String[] args) throws InterruptedException {
//        阻塞队列是线程安全的
        BlockingDeque<String> blockingDeque = new LinkedBlockingDeque<>();
//        阻塞队列核心方法，主要有两个 阻塞队列可用于实现缓冲区、管程等
//        1.put 入队列
        blockingDeque.put("hello1");
        blockingDeque.put("hello2");
        blockingDeque.put("hello3");
        blockingDeque.put("hello4");
        blockingDeque.put("hello5");
//        2.take 出队列
        String result = null;
        result = blockingDeque.take();
        System.out.println(result);
        result = blockingDeque.take();
        System.out.println(result);
        result = blockingDeque.take();
        System.out.println(result);
        result = blockingDeque.take();
        System.out.println(result);
        result = blockingDeque.take();
        System.out.println(result);
        result = blockingDeque.take();
        System.out.println(result);
    }
}
